<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="原料水id" prop="rawWaterId">
        <el-input
          v-model="queryParams.rawWaterId"
          placeholder="请输入原料水id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="PH" prop="PH">
        <el-input
          v-model="queryParams.PH"
          placeholder="请输入PH"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="SS" prop="SS">
        <el-input
          v-model="queryParams.SS"
          placeholder="请输入SS"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="氨氮" prop="nh3N">
        <el-input
          v-model="queryParams.nh3N"
          placeholder="请输入氨氮"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总氮" prop="TN">
        <el-input
          v-model="queryParams.TN"
          placeholder="请输入总氮"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="COD" prop="COD">
        <el-input
          v-model="queryParams.COD"
          placeholder="请输入COD"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="BOD" prop="BOD">
        <el-input
          v-model="queryParams.BOD"
          placeholder="请输入BOD"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="硫氰酸根" prop="thiocyanate">
        <el-input
          v-model="queryParams.thiocyanate"
          placeholder="请输入硫氰酸根"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="硫化物" prop="sulfide">
        <el-input
          v-model="queryParams.sulfide"
          placeholder="请输入硫化物"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="挥发酚" prop="volatilePhenols">
        <el-input
          v-model="queryParams.volatilePhenols"
          placeholder="请输入挥发酚"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="碱度" prop="ALK">
        <el-input
          v-model="queryParams.ALK"
          placeholder="请输入碱度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="氯离子" prop="CI">
        <el-input
          v-model="queryParams.CI"
          placeholder="请输入氯离子"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="石油类" prop="petroleum">
        <el-input
          v-model="queryParams.petroleum"
          placeholder="请输入石油类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="苯" prop="benzene">
        <el-input
          v-model="queryParams.benzene"
          placeholder="请输入苯"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="多环芳烃" prop="PAH">
        <el-input
          v-model="queryParams.PAH"
          placeholder="请输入多环芳烃"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="苯并芘" prop="BaP">
        <el-input
          v-model="queryParams.BaP"
          placeholder="请输入苯并芘"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总氰" prop="TC">
        <el-input
          v-model="queryParams.TC"
          placeholder="请输入总氰"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="createUser">
        <el-input
          v-model="queryParams.createUser"
          placeholder="请输入创建人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新人" prop="updateUser">
        <el-input
          v-model="queryParams.updateUser"
          placeholder="请输入更新人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除标志 0代表未删除" prop="isDeleted">
        <el-input
          v-model="queryParams.isDeleted"
          placeholder="请输入删除标志 0代表未删除"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['imports:imports:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['imports:imports:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['imports:imports:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['imports:imports:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="importsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="原料水id" align="center" prop="rawWaterId" />
      <el-table-column label="类型 原料表数据类型三种类型" align="center" prop="type" />
      <el-table-column label="PH" align="center" prop="PH" />
      <el-table-column label="SS" align="center" prop="SS" />
      <el-table-column label="氨氮" align="center" prop="nh3N" />
      <el-table-column label="总氮" align="center" prop="TN" />
      <el-table-column label="COD" align="center" prop="COD" />
      <el-table-column label="BOD" align="center" prop="BOD" />
      <el-table-column label="硫氰酸根" align="center" prop="thiocyanate" />
      <el-table-column label="硫化物" align="center" prop="sulfide" />
      <el-table-column label="挥发酚" align="center" prop="volatilePhenols" />
      <el-table-column label="碱度" align="center" prop="ALK" />
      <el-table-column label="氯离子" align="center" prop="CI" />
      <el-table-column label="石油类" align="center" prop="petroleum" />
      <el-table-column label="苯" align="center" prop="benzene" />
      <el-table-column label="多环芳烃" align="center" prop="PAH" />
      <el-table-column label="苯并芘" align="center" prop="BaP" />
      <el-table-column label="总氰" align="center" prop="TC" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="创建人" align="center" prop="createUser" />
      <el-table-column label="更新人" align="center" prop="updateUser" />
      <el-table-column label="删除标志 0代表未删除" align="center" prop="isDeleted">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_is_delete" :value="scope.row.isDeleted"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['imports:imports:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['imports:imports:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改原料水检测分类对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="原料水id" prop="rawWaterId">
          <el-input v-model="form.rawWaterId" placeholder="请输入原料水id" />
        </el-form-item>
        <el-form-item label="PH" prop="PH">
          <el-input v-model="form.PH" placeholder="请输入PH" />
        </el-form-item>
        <el-form-item label="SS" prop="SS">
          <el-input v-model="form.SS" placeholder="请输入SS" />
        </el-form-item>
        <el-form-item label="氨氮" prop="nh3N">
          <el-input v-model="form.nh3N" placeholder="请输入氨氮" />
        </el-form-item>
        <el-form-item label="总氮" prop="TN">
          <el-input v-model="form.TN" placeholder="请输入总氮" />
        </el-form-item>
        <el-form-item label="COD" prop="COD">
          <el-input v-model="form.COD" placeholder="请输入COD" />
        </el-form-item>
        <el-form-item label="BOD" prop="BOD">
          <el-input v-model="form.BOD" placeholder="请输入BOD" />
        </el-form-item>
        <el-form-item label="硫氰酸根" prop="thiocyanate">
          <el-input v-model="form.thiocyanate" placeholder="请输入硫氰酸根" />
        </el-form-item>
        <el-form-item label="硫化物" prop="sulfide">
          <el-input v-model="form.sulfide" placeholder="请输入硫化物" />
        </el-form-item>
        <el-form-item label="挥发酚" prop="volatilePhenols">
          <el-input v-model="form.volatilePhenols" placeholder="请输入挥发酚" />
        </el-form-item>
        <el-form-item label="碱度" prop="ALK">
          <el-input v-model="form.ALK" placeholder="请输入碱度" />
        </el-form-item>
        <el-form-item label="氯离子" prop="CI">
          <el-input v-model="form.CI" placeholder="请输入氯离子" />
        </el-form-item>
        <el-form-item label="石油类" prop="petroleum">
          <el-input v-model="form.petroleum" placeholder="请输入石油类" />
        </el-form-item>
        <el-form-item label="苯" prop="benzene">
          <el-input v-model="form.benzene" placeholder="请输入苯" />
        </el-form-item>
        <el-form-item label="多环芳烃" prop="PAH">
          <el-input v-model="form.PAH" placeholder="请输入多环芳烃" />
        </el-form-item>
        <el-form-item label="苯并芘" prop="BaP">
          <el-input v-model="form.BaP" placeholder="请输入苯并芘" />
        </el-form-item>
        <el-form-item label="总氰" prop="TC">
          <el-input v-model="form.TC" placeholder="请输入总氰" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="创建人" prop="createUser">
          <el-input v-model="form.createUser" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="更新人" prop="updateUser">
          <el-input v-model="form.updateUser" placeholder="请输入更新人" />
        </el-form-item>
        <el-form-item label="删除标志 0代表未删除" prop="isDeleted">
          <el-input v-model="form.isDeleted" placeholder="请输入删除标志 0代表未删除" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listImports, getImports, delImports, addImports, updateImports } from "@/api/imports/imports"

export default {
  name: "Imports",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 原料水检测分类表格数据
      importsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        rawWaterId: null,
        type: null,
        PH: null,
        SS: null,
        nh3N: null,
        TN: null,
        COD: null,
        BOD: null,
        thiocyanate: null,
        sulfide: null,
        volatilePhenols: null,
        ALK: null,
        CI: null,
        petroleum: null,
        benzene: null,
        PAH: null,
        BaP: null,
        TC: null,
        createUser: null,
        updateUser: null,
        isDeleted: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询原料水检测分类列表 */
    getList() {
      this.loading = true
      listImports(this.queryParams).then(response => {
        this.importsList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        rawWaterId: null,
        type: null,
        PH: null,
        SS: null,
        nh3N: null,
        TN: null,
        COD: null,
        BOD: null,
        thiocyanate: null,
        sulfide: null,
        volatilePhenols: null,
        ALK: null,
        CI: null,
        petroleum: null,
        benzene: null,
        PAH: null,
        BaP: null,
        TC: null,
        remark: null,
        createUser: null,
        createTime: null,
        updateUser: null,
        updateTime: null,
        isDeleted: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加原料水检测分类"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getImports(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改原料水检测分类"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateImports(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addImports(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除原料水检测分类编号为"' + ids + '"的数据项？').then(function() {
        return delImports(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('imports/imports/export', {
        ...this.queryParams
      }, `imports_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
